package com.waghost.bridalgown.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.waghost.bridalgown.dao.BridalGownDao;
import com.waghost.bridalgown.dao.CommDao;
import com.waghost.bridalgown.entity.BridalGown;
import com.waghost.bridalgown.entity.Comm;
import com.waghost.bridalgown.entity.Result;
import com.waghost.bridalgown.service.BridalGownService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@AllArgsConstructor
@Service
public class IBridalGownService implements BridalGownService {

    private BridalGownDao bridalGownDao;
    private CommDao commDao;

    @Override
    public Result list(Integer c) {
        if (c != null) {
           return Result.success(bridalGownDao.selectList(new QueryWrapper<BridalGown>().eq("category", c)));
        }
        return Result.success(bridalGownDao.selectList(null));
    }

    @Override
    public Result getId(Integer id) {
        return Result.success(bridalGownDao.selectById(id));
    }

    @Override
    public Result add(BridalGown bridalGown) {
        return Result.toAjax(bridalGownDao.insert(bridalGown), "添加成功", "添加错误");
    }

    @Override
    public Result update(BridalGown bridalGown) {
        return Result.toAjax(bridalGownDao.updateById(bridalGown), "修改成功", "修改错误");

    }

    @Override
    public Result delete(Integer id) {
        return Result.toAjax(bridalGownDao.deleteById(id), "删除成功", "删除错误");
    }

    @Override
    public Result listByCategory(Integer category) {
        return Result.success(bridalGownDao.selectList(new QueryWrapper<BridalGown>().eq("category", category)));
    }

    @Override
    public Result listTop() {
        return Result.success(bridalGownDao.selectList(new QueryWrapper<BridalGown>().eq("top", 1)));
    }
}
